using System;
using FlowCanvas;
using FlowCanvas.Nodes;
using NodeCanvas.Framework;
using ParadoxNotion.Design;

namespace Yoozoo.Gameplay.Liberty.Nodes
{
    [Category("Ggame")]
    public class GuideEvent: EventNode
    {
        public static Action<int> OnGuideEvent;

        [RequiredField]
        public BBParameter<int> eventId;
        
        private FlowOutput onReceived;

        public override string name
        {
            get
            {
                return string.Format("{0} ({1})", "GuideEvent", eventId.value);
            }
        }
        
        protected override void RegisterPorts()
        {
            AddFlowInput("start",OnStart);
            
            onReceived = AddFlowOutput("OnReceived");
            AddValueOutput<int>("EventId", () => { return eventId.value; });
        }

        public override void OnPostGraphStarted()
        {
            OnGuideEvent -= OnGuideEventFunc;
            OnGuideEvent += OnGuideEventFunc;
        }

        private void OnStart(Flow f)
        {
            // OnGuideEvent -= OnGuideEventFunc;
            // OnGuideEvent += OnGuideEventFunc;
        }

        private void OnGuideEventFunc(int id)
        {
            if (id == eventId.value)
            {
                onReceived.Call(new Flow());
            }
        }
        
        public override void OnPostGraphStoped()
        {
            OnGuideEvent -= OnGuideEventFunc;
        }
    }
}